import 'dart:convert';

import 'package:base_lib/common/index.dart';
import 'package:common_lib/patient_management/patient_list/patient_list_entity.dart'
    as PatientListBean;

class CommonHttp {
  static HttpManager _httpProxyIns;

  static createHttpProxy(
      {mBaseUrl,
      // ignore: non_constant_identifier_names
      CODE_NAME = "code",
      // ignore: non_constant_identifier_names
      CODE_SUCCESS_VALUE = 0,
      // ignore: non_constant_identifier_names
      MSG_NAME = "message",
      // ignore: non_constant_identifier_names
      REQ_TIME_OUT = 50000,
      // ignore: non_constant_identifier_names
      RESP_TIME_OUT = 50000,
      // ignore: non_constant_identifier_names
      LOG_TAG = "common"}) {
    _httpProxyIns = HttpManager(mBaseUrl,
        CODE_NAME: CODE_NAME,
        CODE_SUCCESS_VALUE: CODE_SUCCESS_VALUE,
        MSG_NAME: MSG_NAME,
        REQ_TIME_OUT: REQ_TIME_OUT,
        RESP_TIME_OUT: RESP_TIME_OUT,
        LOG_TAG: LOG_TAG);
  }

  /// 获取当前医生的所有患者
  static const PEACHUSER_GET_DOCTORPATIENT_ALL =
      "api/peachUser/doctorPatient/getAll";
  // 更新医生的单个线下患者信息
  static const PEACHUSER_POST_DOCTORPATIENT_UPDATE =
      "api/peachUser/doctorPatient/update";
  // 新增医生的单个线下患者信息
  static const PEACHUSER_POST_DOCTORPATIENT_SAVE =
      "api/peachUser/doctorPatient/addOne";
  // 删除医生的单个线下患者信息
  static const PEACHUSER_GET_DOCTORPATIENT_DELETE =
      "api/peachUser/doctorPatient/delete";

  ///获取当前医生的所有患者
  static Future<ResultBody<List<PatientListBean.Datum>>> getDoctorAllPatient(
      String keyID) {
    return _httpProxyIns.get<List<PatientListBean.Datum>>(
        PEACHUSER_GET_DOCTORPATIENT_ALL, (resMap) {
      return PatientListBean.PatientListEntity.fromJson(resMap).data;
    }, queryParams: Map()..['doctorID'] = keyID);
  }

  /// 更新医生的单个线下患者信息
  static Future updatePatientInfo(Map<String, dynamic> params) {
    return _httpProxyIns.postJson(
        PEACHUSER_POST_DOCTORPATIENT_UPDATE, (resMap) {},
        jsonData: json.encode(params));
  }

  /// 新增医生的单个线下患者信息
  static Future savePatientInfo(Map<String, dynamic> params) {
    return _httpProxyIns.postJson(
        PEACHUSER_POST_DOCTORPATIENT_SAVE, (resMap) {},
        jsonData: json.encode(params));
  }

  /// 删除医生的单个线下患者信息
  static Future deletePatientInfo(Map<String, dynamic> params) {
    return _httpProxyIns.get(PEACHUSER_GET_DOCTORPATIENT_DELETE, (resMap) {},
        queryParams: params);
  }
}
